    //
//  SC_PieChartVC.m
//  SCCharts
//
//  Created by Yang on 10/21/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "SC_PieChartVC.h"
#import "SC_PieChartData.h"

@implementation SC_PieChartVC



/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	dataArray = [[NSMutableArray alloc] init];
	[super viewDidLoad];
}

- (void)setViewFrame:(CGRect )frame {
	SC_PieView *view = [[SC_PieView alloc] initWithFrame:frame];
	self.view = view;
	//view.delegate = self;
	[view release];
}
- (void)resetViewFrame:(CGRect )frame {
	[(SC_PieView *)self.view resetFrame:frame];
}
- (void)setData:(NSArray *)data {
	//NSLog(@"setData");
	[(SC_PieView *)self.view resetData:data];
	[dataArray setArray:data];
	//[self showMarkerViews];
}
- (void)showMarkerViews {
	NSLog(@"showMarkerViews");
	float total = 0.0f;
	for (SC_PieChartData *data in dataArray) {
		total += data.value;
		NSLog(@"%f",data.value);
	}
	
	NSArray *array = [(SC_PieView *)self.view dotArray];
	for (int i = 0; i < [array count]; i ++) {
		SC_PieChartData *data = [dataArray objectAtIndex:i];
		SC_PieChartMarkerView *marker = [[SC_PieChartMarkerView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 182.0f, 82.0f)];
		marker.titleLabel.text = data.title;
		marker.countLabel.text = [NSString stringWithFormat:@"%.0f个(%.0f)",data.value,data.value/total * 100];
		marker.overLabel.text = [NSString stringWithFormat:@"超标"];
		NSDictionary *dict = [array objectAtIndex:i];
		[self.view addSubview:marker];
		marker.backgroundColor = [UIColor whiteColor];
		marker.center = CGPointMake([[dict objectForKey:@"x"] floatValue], [[dict objectForKey:@"y"] floatValue]);
		[marker release];
	}
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (NSArray *)getDotArray {
	return [(SC_PieView *)self.view dotArray];
}
- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

#pragma mark SC_PieViewDelegate
- (void)needReloadMarkersFor:(NSArray *)dataArray Dots:(NSArray *)dotArray {
//	NSLog(@"delegate detected");
	//[self showMarkerViews];
}

@end
